package com.boss.salary.controller;

import com.boss.api.dto.ApiResultDTO;
import com.boss.common.base.BasicinfoBaseController;
import com.boss.salary.service.IHomeService;
import com.boss.sys.ca.user.dto.UserDTO;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;

/**
 * <br>Title: 首页
 * <br>Description:
 * <br>Author:
 * <br>Date:
 */
@RestController
@RequestMapping("/homeController")
public class HomeController extends BasicinfoBaseController {

    /**
     * 引入日志框架常量
     */
    private final static Logger logger = LoggerFactory.getLogger(HomeController.class);

    @Autowired
    private IHomeService iHomeService;

    @PostMapping("/getAuditCount")
    public ApiResultDTO getAuditCount(@RequestHeader("tokenid") String tokenid,
                                      @RequestBody List<Map<String, Object>> menuParam) {
        try {
            logger.info(menuParam.toString());
            UserDTO userDTO = getUser(tokenid);
            List<Map<String, Object>> list = iHomeService.getAuditCount(userDTO, menuParam);
            return ApiResultDTO.success(list);
        } catch (Exception e) {
            logger.error(e.getMessage(), e);
            return ApiResultDTO.error(ERROR_RSCODE, "查询异常");
        }
    }

    @GetMapping("/getSalaryMonth")
    public ApiResultDTO getSalaryMonth(@RequestHeader("tokenid") String tokenid){

        try {
            UserDTO userDTO = getUser(tokenid);
            String salary_month = iHomeService.getSalaryMonth(userDTO);
            return ApiResultDTO.success(salary_month);
        } catch (Exception e) {
            logger.error(e.getMessage(), e);
            return ApiResultDTO.error(ERROR_RSCODE, "查询异常");
        }
    }

    @GetMapping("/updateSalaryBackLog")
    public ApiResultDTO updateSalaryBackLog(@RequestParam(value = "id")String id){

        try {
             iHomeService.updateSalaryBackLog(id);
            return ApiResultDTO.success("");
        } catch (Exception e) {
            logger.error(e.getMessage(), e);
            return ApiResultDTO.error(ERROR_RSCODE, "查询异常");
        }
    }
}
